﻿using System.Configuration;

namespace Kaio.Mvc.Routing
{
    public class ConstraintCollection : ConfigurationElementCollection
    {
        public Constraint this[int index]
        {
            get { return base.BaseGet(index) as Constraint; }

            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new Constraint();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((Constraint) element).Name;
        }
    }
}